import { Form } from "antd";
import { FormComponentProps } from "antd/lib/form/Form";
import { Moment } from "moment";
import { Dispatch } from "redux";
import {
  IReducerState_Form,
  IReducerState_TableFilter
} from "../../store/reducer";
import { Reducers } from "../../../../../App";
import {
  formSubmit_addAct,
  formHide_addAct,
  getTableDatasourceAct
} from "../../store/actions";
import { IResBody } from "../../../../../common/config/http";

// 添加时的表单
export interface IForm {
  type: number;
  expiryTime: Moment;
  payMoney: number;
  ownerId: number;
  note: string;
}

interface IPropsState {
  formInfo: IReducerState_Form;
  filter: IReducerState_TableFilter;
}

interface IPropsDispatch {
  hide: (formInfo: IReducerState_Form) => void;
  submit: (formInfo:IReducerState_Form,data: any, callback: (res: IResBody) => void) => void;
  getTableDatasource: (filter: IReducerState_TableFilter) => void;
}

interface IExtra extends FormComponentProps {}

export type TProps = IPropsState & IPropsDispatch & IExtra;

export const mapStateToProps = (state: Reducers): IPropsState => {
  const reducer = state.manageOrderReducer;
  return {
    formInfo: reducer.form_info,
    filter: reducer.table_filter
  };
};

export const mapDispatchToProps = (dispatch: Dispatch): IPropsDispatch => ({
  submit(formInfo:IReducerState_Form,data: any, callback: (res: IResBody) => void) {
    const action: any = formSubmit_addAct(formInfo,data, callback);
    dispatch(action);
  },
  hide(formInfo: IReducerState_Form) {
    const action = formHide_addAct(formInfo);
    dispatch(action);
  },
  getTableDatasource(filter: IReducerState_TableFilter) {
    const action: any = getTableDatasourceAct(filter);
    dispatch(action);
  }
});
